package com.bbva.kyfb.kyfbfo.rest;

import javax.annotation.Resource;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import com.bbva.jee.arq.spring.core.filtro.InicioSesionMock;
import com.bbva.kyfb.kyfbdto.firmas.bo.InfoAssistantDto;
import com.bbva.kyfb.kyfbdtofo.FicheroRequest;
import com.bbva.kyfb.kyfbdtofo.fachada.interfaces.v01.ExecuteServiceV01;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/applicationContext.xml" })
public class ServiciosRest {
	
	protected RestTemplate restTemplate;
	
	@Resource(name="servicioEjecucionHttpHTTPClient")
	ExecuteServiceV01 executeServiceV01;
	
	@Test
	@InicioSesionMock
	public void ficheroInvokerTest() {
		FicheroRequest ficheroRequest = new FicheroRequest();
		
		//TODO: reemplazar con los valores correctos
		ficheroRequest.setIdOrden("hlgghic7");
		ficheroRequest.setNumItem("468898710394");
		ficheroRequest.setTipoFirma("FS");
		ficheroRequest.setTipoOrden("TRA");
		ficheroRequest.setCanal("0023");
		ficheroRequest.setSubproducto("1");
		ficheroRequest.setBancoInterno("0001");
		ficheroRequest.setReferencia("20027999");
		
		try {
			InfoAssistantDto infoAssistantDto = executeServiceV01.executeFile(ficheroRequest);
			System.out.println(infoAssistantDto.getCodError());
		}
		catch(Exception e) {
			System.out.println(e);
		}
	}
	
	
	@Test
	@Ignore
	public void test() {
		// comentado temporalmente para el despliegue en jenkins
		
		String url = "http://localhost:8080/kyfb_mult_web_kyfbws_03/services/rest/v01/service/execution/file/";

		HttpHeaders headers = new HttpHeaders();
		headers.set("Contexto", "{ }");
		
		HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
		
		  restTemplate = new RestTemplate(); 
//		  Article article = restTemplate.getForObject("http://localhost:8080/backend-nekperu15739/article", Article.class); 
//		  System.out.println(article);
		  
//		  String employeeDTO = restTemplate.getForObject(url, String.class);
		  
		  ResponseEntity<InfoAssistantDto> entity2 = restTemplate.exchange(url, HttpMethod.POST, entity, InfoAssistantDto.class);
		  
		  System.out.println(entity2);
	}
	
	@Test
	@Ignore
	public void testPost(){
		restTemplate = new RestTemplate();
//		restTemplate.po
		
		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.set("Contexto", "{ }");

////		User user = new User();
//
		String url = "http://localhost:8080/kyfb_mult_web_kyfbws_03/services/rest/v01/service/execution/file/";
//		
////		HttpEntity requestEntity = new HttpEntity<MultiValueMap(user, requestHeaders);
////		String s = restTemplate.exchange(url, method, requestEntity, String.class);
//		
//		
//		
		MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
		postParameters.add("ficheroRequest", " ");
//		postParameters.add("lastName", " ");

		HttpEntity<MultiValueMap<String, String>> requestEntity2 = new HttpEntity<MultiValueMap<String, String>>(postParameters, requestHeaders);

		ResponseEntity<String> s1 = restTemplate.exchange(url, HttpMethod.POST, requestEntity2, String.class);
		
		System.out.println(s1);
		
		
//		Map<String, String> vars = new HashMap<String, String>();
//		vars.put("hotel", "42");
//		vars.put("booking", "21");
//		String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class, vars);
		
//		MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
//		headers.add("Contexto", "{ }");
//		
//		MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
//		parameters.add("ficheroRequest", " ");
		
		 

//		restTemplate.postForEntity(url, request, responseType);
		
//		HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(parameters, headers);
//		Class<Object> responseType = null;
		
//		restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
	}

}
